1.
val rdd=sc.parallelize(1 to 100)
val rdd1=rdd.filter(_>50).map(_*2)
println(rdd1.collect().mkString(","))

2.
val rdd=sc.textFile("file:///home/hadoop/word.txt")
val rdd1=rdd.fltMap(_.toLowerCase.split(" "))
println(rdd1.collect.mkString(","))

3.
val rdd=sc.parallelize(Seq(("Alice", 90), ("Bob", 80), ("Charlie", 70), ("Alice", 85), ("Bob", 95)))
val rdd1=rdd.reduceByKey(_+_)
println(rdd1.collect.mkString(","))

4.
class CustomPartitioner extends Partitioner{
     override def numPartitions:Int=2
     override def getPartition(key:Any):Int={
        key match {
      case str: String =>
        if (str.length <= 5) 0 else 1
      case _ => throw new IllegalArgumentException("Expected a string")
    }
  }
}
val partitionedRDD = rdd.map(str => (str, 1)).partitionBy(new CustomPartitioner).persist()
val resultRDD = partitionedRDD.mapPartitions(iter => Iterator(iter.size))
resultRDD.collect().foreach(println)

val partitionedRDD = rdd.map(str => (str, 1)).partitionBy(new CustomPartitioner).persist()
val resultRDD = partitionedRDD.mapPartitions(iter => Iterator(iter.size))
resultRDD.collect().foreach(println)

